package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.DialogBox;
import com.base.service.DialogBoxService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;

/**
 * 添加滚动文字信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_DialogBox {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private DialogBoxService dialogBoxService; // 商城滚动文字信息

	// 添加商城滚动文字
	@RequestMapping(value = "/toAddDialogBox", method = RequestMethod.POST)
	public @ResponseBody int toAddDialogBox(HttpServletRequest request, String text, String userid)
			throws IOException, ParseException {
		String adminUserId = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (adminUserId == null) return -1; // 未登录
		if (dialogBoxService.selectByParentId(userid).size() >= 1) return -2;// 判断是否存在1条
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置商城滚动文字信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return dialogBoxService.insertSelective(new DialogBox(Produce.getUUID(), text, userid)); // 添加
	}
}
